<template>
	<view class="page">
		<view class="title">
			<label class="title-item1">{{item.shopName}} · 采购 {{item.shopPurchaseNum}} {{item.shopPurchaseNumUnit}} </label>
			<label class="title-item2">{{item.readTimes}}次浏览</label>
		</view>
		<view class="title">
			<label class="title-item3">品类名：{{item.shopName}} </label>
			<label class="title-item4">类型：{{item.purchase == '0' ? "预购" : "急购"}}</label>
		</view>
		
		
		<view class="title">
			<label class="title-item3">采购人：{{item.preUser ? item.preUser.nickName:"匿名"}}</label>
			<label class="title-item3">采购截止时间：{{item.purchaseEndDayStr}}</label>
		</view>
		
		<view class="title"> 
			<label class="title-item3">采购价：{{item.purchasePrice}} {{item.purchasePriceUnit}}</label>
			<label class="title-item3">指定产地：{{item.address}}</label>
		</view>
		<view class="title">
			<label class="title-item3">采购身份：{{item.shopUserType}}</label>
			<label class="title-item3">单号：NO{{item.id}}</label>
		</view>
		<view class="title">
			<label class="title-item3">发布时间：{{item.createDate}}</label>
			 
		</view>
 
		<view class="title">
			<label class="title-item1">详细描述</label>
		</view>
		<view class="title">
			<label class="title-item3">{{item.shopDescription}}</label>
		</view>
	</view>
	<view class="end">
		<view class="button">
			<view class="view-box">
				<image class="icon" v-if="item.like" src="../../../../static/img/收藏2.png" @click="likeClick()"/>
				<image class="icon" v-else src="../../../../static/img/收藏0.png" @click="likeClick()"/>
				<label class="title">收藏</label>
			</view>
			<view class="view-box" @click="badCall()">
				<image class="icon" src="../../../../static/img/tabbar/newsactive.png"></image>
			<label class="title">投诉</label>
			</view>
			<view class="view-box2"  @click="wxContact()">
				<label class="title2">微信沟通</label>
			</view>
			<view class="view-box3" @click="call()">
				<label class="title">电话联系</label>
			</view>
		</view>
	</view>
	 
</template>

<script>
	
	import utils from '@/utils/requset.js'
	import operate from '@/common/operate.js'

	export default {
		data() {
			 return {
					id:0,
					item:{},
			        go_latitude: '', //这里设置成了字符型，如果直接用uni.openLocation打开地图就会没有任何反应
			        go_longitude: '' //这里设置成了字符型，如果直接用uni.openLocation点击打开地图时没有任何反应
			    }
		},
		onLoad(options) {
			this.id=options.id;
			//请求登录
			var header = {},
				data = {
					id:this.id,
					userId : uni.getStorageSync("userInfo").id,
				},
				url = "/purchase/preOrder/detail", 
				method = "POST";
			if (method) {
				method = method.toUpperCase(); 
				if (method == "POST") {
					header = {
					   'Content-Type': "application/json"
					};
				} else {
					header = {
						'Content-Type': "application/json"
					};
				}	
			}
						 
			 uni.request({
				url: operate.api + url,		
				data: data,
				method: method,
				header: header,
				success: (res) => {
					console.log(JSON.stringify(res))
					if(res.statusCode && res.statusCode ==200){
						if(res.data.data){
							this.item = res.data.data
						 
						} 
					}else{
						console.log("数据状态码！=200")
					}
					
				},fail(res2) {
					 
				},complete() {
					 
				}
			})
			
		},
		 
		onShow() {
			//请求登录
			var header = {},
				data = {
					id:this.id
				},
				url = "/purchase/preOrder/updateReadTimes", 
				method = "POST";
			if (method) {
				method = method.toUpperCase(); 
				if (method == "POST") {
					header = {
					   'Content-Type': "application/json"
					};
				} else {
					header = {
						'Content-Type': "application/json"
					};
				}	
			}	 
			 uni.request({
				url: operate.api + url,		
				data: data,
				method: method,
				header: header,
				success: (res) => {
					if(res.statusCode && res.statusCode ==200){
					}else{
						console.log("数据状态码！=200")
					}
					
				}
			})
		},
		
		methods: {
			
		 
		badCall(){
			uni.makePhoneCall({
				phoneNumber:18438610533
			})
		},
		wxContact(){
			uni.navigateTo({
				 url:'/pages/webview/webview'
			});
		},
		call(){
			//获取沟通次数判断
			if(uni.getStorageSync("userInfo").id){
				 
			}else{
				uni.navigateTo({
					url: '/pages/loginOnlyPhone/loginOnlyPhone'
				})
				return;
			}
			//请求登录
			var header = {},
				data = {
					id:this.item.preUser.id
				},
				url = "/purchase/preUser/updateCallNumToday", 
				method = "POST";
			if (method) {
				method = method.toUpperCase(); 
				if (method == "POST") {
					header = {
					   'Content-Type': "application/json"
					};
				} else {
					header = {
						'Content-Type': "application/json"
					};
				}	
			}	 
			 uni.request({
				url: operate.api + url,		
				data: data,
				method: method,
				header: header,
				success: (res) => {
					if(res.statusCode && res.statusCode ==200 && res.data.data.callNumToday >= res.data.data.callLimitNum){
						uni.showModal({
						  title: '提示',
						  content: "采购方今日电话被打爆了!"+"已超过对方设置的阀值，请明日再来吧",
						  showCancel:false,
						  success: function (r) {
							  
						  }
						});
					}else{
						uni.makePhoneCall({
							phoneNumber:this.item.registPhone
						})
					}
				}
			})

		},
		
		
		copy:function(){
			let name = "雷&玓";
			uni.showModal({
			  title: '是否复制下面微信号',
			  content: "雷&玓",
			  success: function (res) {
				  if (res.confirm) {
					  console.log('用户点击确认'+name);
					  uni.setClipboardData({
						  data: name,
						  success: function () {
							  console.log(name);
						  }
					  });
				  } else if (res.cancel) {
					  console.log('用户点击取消');
				  }
			  }
			});
		},
		
		/**
		 * 转评赞藏
		 */
		likeClick(){
			let userId = uni.getStorageSync("userInfo").id;
			if(userId){
				 
			}else{
				uni.navigateTo({
					url: '/pages/loginOnlyPhone/loginOnlyPhone'
				})
				return;
			}
			// 操作类型： 0:顶  1：赞 2：评论 3：转发 4：收藏 5:举报
			// type 0:预购单   1:预售单
			let id = this.id;
			var header = {},
				data = {
					preUserIdTarget : uni.getStorageSync("userInfo").id,
					pubUserIdTarget : this.item.preUser.id,
					preOrderId: id,
					operateType : 4,
					type : 0,
				},
				url = "/purchase/shopOrOrderMyLike/saveOrUpdate", 
				method = "POST";
			if (method) {
				method = method.toUpperCase(); 
				if (method == "POST") {
					header = {
					   'Content-Type': "application/json"
					};
				} else {
					header = {
						'Content-Type': "application/json"
					};
				}
			}
						 
			 uni.request({
				url: operate.api + url,		
				data: data,
				method: method,
				header: header,
				success: (res) => {
					if(res.statusCode && res.statusCode ==200){
						console.log(res)
						item.like = !item.like
					}else{
						console.log("数据状态码！=200")
					}
					
				}
			})
		},
			
		
		}
	}
</script>

<style>
	 uni-button{
	 	background-color:#fff !important;
	 	font-size: 14px;
	 	color: #fff;
	 }
	 uni-button:after {
	 	border: 1px solid #fff;
	 }
	 .end{
		 position: fixed;
		 bottom: 0;
		 width: 100%;
		 margin-bottom: 10px;
	 }
	 
	.page{
		font-size: 13px;
		letter-spacing: 0px;
		line-height: 20px;
		margin:  10px;
		height: 100%;
	}
	.page label{
		font-size: 13px;
	}
	 
	.title{
		display: flex;
		margin-top: 15px;
	}
	.title-item1{
		margin-top: 15px;
		font-size: 16px !important;
		font-weight: 700;
		letter-spacing: 0px;
		line-height: 16px;
		color: rgba(42, 47, 51, 1);
		flex: 1;
		text-align: left;
		font-weight: bold;
	}
	.title-item2{
		flex: 1;
		text-align: right;
		margin-top: 15px;
	}
	.title-item3{
		flex: 1;
		text-align: left;
	}
	.title-item3-time{
		flex: 1;
		text-align: left;
		color: #43CF7C;
	}
	.title-item4{
		flex: 1;
		text-align: left;
		color: #43CF7C;
	}
	
	.button{
		bottom: 0;
		display: flex;
		width: 100%;
	}
	
	.view-box {
		flex:1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: #fff;
	}
	.view-box2 {
		flex:2;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: #43CF7C;
		margin-left: 10px;
		margin-right: 10px;
		border-radius: 3px;
	}
	.view-box2 label{
		color: #fff;
		font-weight: bold;
		font-size: 13px;
	}
	
	.view-box3 label{
		color: #fff;
		font-weight: bold;
		font-size: 13px;
	}
	.view-box3 {
		flex:2;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: #00B2FF;
		border-radius: 5px;
		margin-left: 10px;
		margin-right: 10px;
		
	}
	.icon {
		width: 7vw;
		height: 7vw;
	}

	.title {
		margin-top: 10rpx;
		font-size: 20upx;
		color: #8f8f94; 
	}

	
</style>
